﻿using Domain.Entitys;
using Domain.Repositorys;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EFCore.Repositorys
{
    public class SGDRepositoty : ISGDRepositoty
    {
        private readonly MyDbContext myDbContext;

        public SGDRepositoty(MyDbContext myDbContext)
        {
            this.myDbContext = myDbContext;
        }
        /// <summary>
        /// 添加薪酬发放详细信息数据
        /// </summary>
        /// <param name="sGDs"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public async Task<int> SGDAddAsync(List<SGD> sGDs)
        {
            foreach (var sGD in sGDs)
            {
                myDbContext.SGD.Add(sGD);
            }
            return await myDbContext.SaveChangesAsync();
        }

        /// <summary>
        /// 根据薪酬发放编号查询数据薪酬详细数据
        /// </summary>
        /// <param name="sid"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public async Task<List<SGD>> SGDBySidAsync(string sid)
        {
            return await myDbContext.SGD.Where(s => s.SalaryGrantId == sid).ToListAsync();
        }

        /// <summary>
        /// 修改薪酬发放详细数据
        /// </summary>
        /// <param name="sGDs"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public async Task<int> SGDUpdateAsync(List<SGD> sGDs)
        {
            foreach (var item in sGDs)
            {
                myDbContext.SGD.Update(item);
            }
            return await myDbContext.SaveChangesAsync();
        }
    }
}
